home *** CD-ROM | disk | FTP | other *** search
- Path: newsflash.concordia.ca!not-for-mail
- From: Didier Guillevic <didier@cenparmi.concordia.ca>
- Newsgroups: comp.lang.c++
- Subject: Template Class Static Members Initialization
- Date: Wed, 27 Mar 1996 11:34:08 -0500
- Organization: CENPARMI (Centre for Pattern Recognition and Machine Intelligence)
- Message-ID: <31596E00.41C67EA6@cenparmi.concordia.ca>
- NNTP-Posting-Host: jofa.cenparmi.concordia.ca
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4m)
- CC: didier
-
- Hi,
-
- Having troubles with the initialization of static members of a template class.
- (C++ Primer, S.B. Lippman, 2nd edition, reprint June 93, Section 7.5, pp.369-371)
- Any idea if that's due to my compiler or ?! Would that compile on yours?
- Here is a simple example that will not compile with g++:
-
- ------
- #include <iostream.h>
-
- template <class T>
- class Test
- {
- private:
- T n;
- public:
- Test( T i ) : n(i) { count++; }
- static int count;
- };
-
- template <class T>
- int Test<T>::count = 0;
-
- int main(int argc, char **argv)
- {
- Test<int> t1(1);
- Test<double> t2(2.0);
-
- cout << Test<int>::count << endl;
- }
- ------
-
- The compiler complains with the following:
-
- test.cc:14: sorry, not implemented: static data member templates
- test.cc:14: end of file read inside definition
-
- The non-template version of class Test compiles just fine.
- The compiler seems to complain that the class Test<int> and
- Test<double> have not yet been instantiated. But this is the
- syntax adopted in Lippman's book.
-
- Thanks for any help.
-
- Didier
- --------------------------------------------------------------
- Didier Guillevic
- CENPARMI, Suite GM-606, Concordia University
- 1455 de Maisonneuve West, Montreal, QC, H3G 1M8, Canada
- tel: 1 (514) 848-2843, fax: 1 (514) 848-4522
- url: http://www.cenparmi.concordia.ca/~people/didier/
- --------------------------------------------------------------
-